home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / jpegsrc4.zip / JPEGDATA.H < prev    next >
C/C++ Source or Header  |  1992-12-01  |  40KB  |  931 lines

  1. /*
  2.  * jpegdata.h
  3.  *
  4.  * Copyright (C) 1991, 1992, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file defines shared data structures for the various JPEG modules.
  9.  */
  10.  
  11.  
  12. /*
  13.  * You might need to change some of the following declarations if you are
  14.  * using the JPEG software within a surrounding application program
  15.  * or porting it to an unusual system.
  16.  */
  17.  
  18.  
  19. /* If the source or destination of image data is not to be stdio streams,
  20.  * these types may need work.  You can replace them with some kind of
  21.  * pointer or indicator that is useful to you, or just ignore 'em.
  22.  * Note that the user interface and the various jrdxxx/jwrxxx modules
  23.  * will also need work for non-stdio input/output.
  24.  */
  25.  
  26. typedef FILE * JFILEREF;    /* source or dest of JPEG-compressed data */
  27.  
  28. typedef FILE * IFILEREF;    /* source or dest of non-JPEG image data */
  29.  
  30.  
  31. /* These defines are used in all function definitions and extern declarations.
  32.  * You could modify them if you need to change function linkage conventions,
  33.  * as is shown below for use with C++.  Another application would be to make
  34.  * all functions global for use with code profilers that require it.
  35.  * NOTE: the C++ test does the right thing if you are reading this include
  36.  * file in a C++ application to link to JPEG code that's been compiled with a
  37.  * regular C compiler.  I'm not sure it works if you try to compile the JPEG
  38.  * code with C++.
  39.  */
  40.  
  41. #define METHODDEF static    /* a function called through method pointers */
  42. #define LOCAL      static    /* a function used only in its module */
  43. #define GLOBAL            /* a function referenced thru EXTERNs */
  44. #ifdef __cplusplus
  45. #define EXTERN      extern "C"    /* a reference to a GLOBAL function */
  46. #else
  47. #define EXTERN      extern    /* a reference to a GLOBAL function */
  48. #endif
  49.  
  50.  
  51. /* Here is the pseudo-keyword for declaring pointers that must be "far"
  52.  * on 80x86 machines.  Most of the specialized coding for 80x86 is handled
  53.  * by just saying "FAR *" where such a pointer is needed.  In a few places
  54.  * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
  55.  */
  56.  
  57. #ifdef NEED_FAR_POINTERS
  58. #define FAR  far
  59. #else
  60. #define FAR
  61. #endif
  62.  
  63.  
  64.  
  65. /* The remaining declarations are not system-dependent, we hope. */
  66.  
  67.  
  68. /*
  69.  * NOTE: if you have an ancient, strict-K&R C compiler, it may choke on the
  70.  * similarly-named fields in Compress_info_struct and Decompress_info_struct.
  71.  * If this happens, you can get around it by rearranging the two structs so
  72.  * that the similarly-named fields appear first and in the same order in
  73.  * each struct.  Since such compilers are now pretty rare, we haven't done
  74.  * this in the portable code, preferring to maintain a logical ordering.
  75.  */
  76.  
  77.  
  78.  
  79. /* This macro is used to declare a "method", that is, a function pointer. */
  80. /* We want to supply prototype parameters if the compiler can cope. */
  81. /* Note that the arglist parameter must be parenthesized! */
  82.  
  83. #ifdef PROTO
  84. #define METHOD(type,methodname,arglist)  type (*methodname) arglist
  85. #else
  86. #define METHOD(type,methodname,arglist)  type (*methodname) ()
  87. #endif
  88.  
  89. /* Forward references to lists of method pointers */
  90. typedef struct External_methods_struct * external_methods_ptr;
  91. typedef struct Compress_methods_struct * compress_methods_ptr;
  92. typedef struct Decompress_methods_struct * decompress_methods_ptr;
  93.  
  94.  
  95. /* Data structures for images containing either samples or coefficients. */
  96. /* Note that the topmost (leftmost) index is always color component. */
  97. /* On 80x86 machines, the image arrays are too big for near pointers, */
  98. /* but the pointer arrays can fit in near memory. */
  99.  
  100. typedef JSAMPLE FAR *JSAMPROW;    /* ptr to one image row of pixel samples. */
  101. typedef JSAMPROW *JSAMPARRAY;    /* ptr to some rows (a 2-D sample array) */
  102. typedef JSAMPARRAY *JSAMPIMAGE;    /* a 3-D sample array: top index is color */
  103.  
  104.  
  105. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  106. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  107.  
  108. typedef JCOEF JBLOCK[DCTSIZE2];    /* one block of coefficients */
  109. typedef JBLOCK FAR *JBLOCKROW;    /* pointer to one row of coefficient blocks */
  110. typedef JBLOCKROW *JBLOCKARRAY;        /* a 2-D array of coefficient blocks */
  111. typedef JBLOCKARRAY *JBLOCKIMAGE;    /* a 3-D array of coefficient blocks */
  112.  
  113. typedef JCOEF FAR *JCOEFPTR;    /* useful in a couple of places */
  114.  
  115.  
  116. /* The input and output data of the DCT transform subroutines are of
  117.  * the following type, which need not be the same as JCOEF.
  118.  * For example, on a machine with fast floating point, it might make sense
  119.  * to recode the DCT routines to use floating point; then DCTELEM would be
  120.  * 'float' or 'double'.
  121.  */
  122.  
  123. typedef JCOEF DCTELEM;
  124. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  125.  
  126.  
  127. /* Types for JPEG compression parameters and working tables. */
  128.  
  129.  
  130. typedef enum {            /* defines known color spaces */
  131.     CS_UNKNOWN,        /* error/unspecified */
  132.     CS_GRAYSCALE,        /* monochrome (only 1 component) */
  133.     CS_RGB,            /* red/green/blue */
  134.     CS_YCbCr,        /* Y/Cb/Cr (also known as YUV) */
  135.     CS_YIQ,            /* Y/I/Q */
  136.     CS_CMYK            /* C/M/Y/K */
  137. } COLOR_SPACE;
  138.  
  139.  
  140. typedef struct {        /* Basic info about one component */
  141.   /* These values are fixed over the whole image */
  142.   /* For compression, they must be supplied by the user interface; */
  143.   /* for decompression, they are read from the SOF marker. */
  144.     short component_id;    /* identifier for this component (0..255) */
  145.     short component_index;    /* its index in SOF or cinfo->comp_info[] */
  146.     short h_samp_factor;    /* horizontal sampling factor (1..4) */
  147.     short v_samp_factor;    /* vertical sampling factor (1..4) */
  148.     short quant_tbl_no;    /* quantization table selector (0..3) */
  149.   /* These values may vary between scans */
  150.   /* For compression, they must be supplied by the user interface; */
  151.   /* for decompression, they are read from the SOS marker. */
  152.     short dc_tbl_no;    /* DC entropy table selector (0..3) */
  153.     short ac_tbl_no;    /* AC entropy table selector (0..3) */
  154.   /* These values are computed during compression or decompression startup */
  155.     long true_comp_width;    /* component's image width in samples */
  156.     long true_comp_height;    /* component's image height in samples */
  157.     /* the above are the logical dimensions of the downsampled image */
  158.   /* These values are computed before starting a scan of the component */
  159.     short MCU_width;    /* number of blocks per MCU, horizontally */
  160.     short MCU_height;    /* number of blocks per MCU, vertically */
  161.     short MCU_blocks;    /* MCU_width * MCU_height */
  162.     long downsampled_width;    /* image width in samples, after expansion */
  163.     long downsampled_height; /* image height in samples, after expansion */
  164.     /* the above are the true_comp_xxx values rounded up to multiples of */
  165.     /* the MCU dimensions; these are the working dimensions of the array */
  166.     /* as it is passed through the DCT or IDCT step.  NOTE: these values */
  167.     /* differ depending on whether the component is interleaved or not!! */
  168. } jpeg_component_info;
  169.  
  170.  
  171. /* DCT coefficient quantization tables.
  172.  * For 8-bit precision, 'INT16' should be good enough for quantization values;
  173.  * for more precision, we go for the full 16 bits.  'INT16' provides a useful
  174.  * speedup on many machines (multiplication & division of JCOEFs by
  175.  * quantization values is a significant chunk of the runtime).
  176.  * Note: the values in a QUANT_TBL are always given in zigzag order.
  177.  */
  178. #ifdef EIGHT_BIT_SAMPLES
  179. typedef INT16 QUANT_VAL;    /* element of a quantization table */
  180. #else
  181. typedef UINT16 QUANT_VAL;    /* element of a quantization table */
  182. #endif
  183. typedef QUANT_VAL QUANT_TBL[DCTSIZE2];    /* A quantization table */
  184. typedef QUANT_VAL * QUANT_TBL_PTR;    /* pointer to same */
  185.  
  186.  
  187. typedef struct {        /* A Huffman coding table */
  188.   /* These two fields directly represent the contents of a JPEG DHT marker */
  189.     UINT8 bits[17];        /* bits[k] = # of symbols with codes of */
  190.                 /* length k bits; bits[0] is unused */
  191.     UINT8 huffval[256];    /* The symbols, in order of incr code length */
  192.   /* This field is used only during compression.  It's initialized FALSE when
  193.    * t